import sqLdStationsApi from '../../api/sqLdStations'

export const LdMixins = {
  components: {},
  data() {
    return {
      ldBaseInfoData: [
        {label: '控制箱总数', value: '-', unit: '盏'},
        {label: '亮灯控制箱数', value: '-', unit: '盏'},
        {label: '亮灯时长', value: '-', unit: ' '},
        {label: '亮灯率', value: '-', unit: '%'}
      ],
      ldlvData: {name: [], value: []},
      ldLeftBottomData: [],
      ldRightBottomData: [],
      ldMidPoints: [],
      ldKzxInfoVisible: false,
      poinstTmp: {
        clearFlag: true,
        fitViewFlag: false,
        clickFlag: true,
        radius: 7,
        fillColor: 'rgba(0,255,0,1)',
        fillOpacity: 1}
    }
  },
  methods: {
    // 进入页面时执行
    openLdPage() {
      this.getData()
    },
    getData() {
      sqLdStationsApi.getLdStationsTotal()
        .then(res => {
          const data = res.data
          this.ldBaseInfoData = [
            {label: '控制箱总数', value: data.leftTop.ld_station_total, unit: '盏'},
            {label: '亮灯控制箱数', value: data.leftTop.last_day_light_count, unit: '盏'},
            {label: '亮灯时长', value: data.leftTop.time, unit: ' '},
            {label: '亮灯率', value: data.leftTop.last_day_light_ratio, unit: '%'}
          ]
          this.ldlvData = {name: [], value: []}
          for (let i = 0; i < data.rightTop.report_date.length; i++) {
            this.ldlvData.name.push(data.rightTop.report_date[i])
            this.ldlvData.value.push(data.rightTop.light_ratio[i])
          }

          this.ldLeftBottomData = data.leftBotton

          this.ldRightBottomData = data.rightBotton

          this.ldMidPoints = data.midPoint
          this.$refs.map.addCircleMarkers(this.ldMidPoints, 'ldKzx', this.poinstTmp)
        })
        .catch(() => {

        })
    },
    handleLdShowAllKzx(item) {
      if (item.label === '控制箱总数') {
        this.$refs.map.addCircleMarkers(this.ldMidPoints, 'ldKzx', this.poinstTmp)
      }
    },
    // 点击分组展示详细点分布
    ldLeftBottomClick(id) {
      sqLdStationsApi.getLdStationsByGroupId(id)
        .then(res => {
          this.ldStationsGroupData = res.data
          this.$refs.map.addCircleMarkers(this.ldStationsGroupData, 'ldKzx', this.poinstTmp)
        })
        .catch(() => {

        })
    },
    ldRightBottomClick(item) {
      console.log('item-->', item)
      this.$refs.map.addCircleMarkers([item], 'ldKzx', this.poinstTmp)
    }
  }
}
